<?php
defined('DCS_ROOT') or exit('Access Denied');

class main {

	function __construct() {
		$url = getUrl();
		$action = $url['action'];
		require_once(APP_PATH."model/admin/init.php" );		
		if($action == 'left'){
			exit($this->left());
		}elseif($action == 'toolbar'){
			exit($this->toolbar());
		}elseif($action == 'welcome'){
			exit($this->welcome());
		}elseif($action == 'main'){
			exit($this->defaultAction());
		}elseif($action == 'logout'){
			$this->logout();
			exit();
		}else{
			error('未定义操作。');
		}
	}

	function defaultAction(){		
		$tpl = new Template("admin/main/main.htm" );		
		$tpl->output();
	}

	function left(){
		$tpl = new Template("admin/main/left.htm" );
		$username = getAdmin();
		if($username == 'admin'){
			$globlaVar['user'] = '<LI><a href="member/list">帐户列表</A>
			<LI><a href="'.ADMIN.'member/add">新增帐户</A>
			';			
		}
		$tpl->assign($globlaVar);
		$tpl->output();
	}

	function toolbar(){
		$tpl = new Template("admin/main/toolbar.htm" );
		$username = getAdmin();
		$globlaVar['username'] = $username;
		$tpl->assign($globlaVar);
		$tpl->output();
	}

	function logout(){
		session_start();
		$username = $_SESSION['adminuser'];
		if(empty($username)){
			location(ADMIN_PATH);
		}else{
			unset($_SESSION['adminuser']);
			message('您已成功退出系统。','/admin');
			exit();
		}
		$tpl->output();
	}
}
?>
